<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/9/21
 * Time: 9:47
 * 上传广告图的动作
 */

require('../include/init.inc.php');
$method = $uploadfile = '';
extract($_REQUEST, EXTR_IF_EXISTS);

$img_str = '';
if (Common::isPost()) {

    if (!$uploadfile) {
        Common::exitWithError(ErrorMessage::ADVERT_NOT_EXIST, "one_page_shop/home_advert.php");
    }

    if ($uploadfile) {
        $img_str = $uploadfile;
    }

    $result = Shop::getInfo();
    if (!$result) {
        Common::exitWithError(ErrorMessage::SHOPINFO_NOT_EXIST, "one_page_shop/home_advert.php");
    }

    $ret = Shop::updateSpec($img_str);//广告图每次上传都会覆盖之前的
    if ($ret) {
        SysLog::addLog(UserSession::getUserName(), 'Update', 'ImagesAdd', $products_model, json_encode($up_data));
        Common::exitWithSuccess('上传完成', 'one_page_shop/product_add_advert.php');
    } else {
        OSAdmin::alert("error");
    }
}

$confirm_html = OSAdmin::renderJsConfirm("icon-remove");
Template::assign('osadmin_action_confirm', $confirm_html);
Template::display('one_page_shop/add_advert.tpl');